/*
 * @Author: LJH003 13179754+ljh003@user.noreply.gitee.com
 * @Date: 2025-05-15 13:39:28
 * @LastEditors: LJH003 13179754+ljh003@user.noreply.gitee.com
 * @LastEditTime: 2025-06-18 21:39:38
 * @FilePath: \ai-assistant-admin\src\api\user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import request from '@/utils/request'
import type { UserInfo } from '@/utils/storage'

// 登录接口参数
export interface LoginParams {
  username: string
  password: string
}

// 用户列表查询参数
export interface UserListParams {
  current: number
  pageSize: number
  username?: string
  realName?: string
  role?: string
}

// 用户表单数据
export interface UserFormData {
  id?: number | string
  username: string
  password?: string
  realName: string
  role: string
  avatar?: string
}

// 登录
export function login(data: LoginParams) {
  return request.post<{
    code: number
    data: { token: string; userInfo: UserInfo }
    message: string
  }>('/authUser/doLogin', data)
}

// 获取用户信息
export function getUserInfo(id: number | string) {
  return request.get<{
    code: number
    data: UserInfo
    message: string
  }>(`/authUser/get/${id}`)
}

// 获取用户列表
export function getUserList(params: UserListParams) {
  return request.post<{
    code: number
    data: {
      total: number
      result: UserInfo[]
    }
    message: string
  }>('/authUser/page', params)
}

// 创建用户
export function createUser(data: UserFormData) {
  return request.post('/authUser/create', data)
}

// 更新用户
export function updateUser(data: UserFormData) {
  return request.post('/authUser/update', data)
}

// 删除用户
export function deleteUser(id: number | string) {
  return request.delete(`/authUser/delete/${id}`)
}